<?php 
/**********************************************/ 
/* CZUser InfoV5 Universal Block              */ 
/*                                            */ 
/* (c) 2002-2004 by Codezwiz Network, LLC.    */ 
/* http://www.codezwiz.com                    */ 
/*                                            */ 
/**********************************************/ 
if (eregi( "block-CZUser-Info.php", $_SERVER['SCRIPT_NAME'])) 
{ 
    die("Access Denied"); 
} 

   // Some global definitions 
   global $user, $prefix, $db, $gfx_chk, $admin, $userinfo, $Version_Num, $admin_file, $currentlang;

$showpms = "1"; //1 ozel mesajlar acik - 0 kapali  
$showmost = "1"; //1 En fazla ayni anda bagli kisi saysi gosterimi acik - 0 kapali 
$dopmpopup = "0"; //1 popup acik- 0 kapali 
$useavatars = "1"; //1 kullanici profil resmi acik - 0 kapali
$usebbranks = "0"; //1 kullanci seviyesi gosterimi acik - 0 kapali
$showonlyadmin = "1"; //1 kim nerde fonksiyonu acik - 0 sadece yoneticiler gorebilir.
$showpoints = "1"; //1 puan datasi acik - 0 kapali
$sitepoints = "points"; //Bunlar kullandiginiz puanlardir. (EX: points, user_points) 


   $content = "";
   getusrinfo($user);
   
  
//Include the language
 if (file_exists("language/CZUser-Info/CZUser-Info-$currentlang.php")) {
    include("language/CZUser-Info/CZUser-Info-$currentlang.php");
   } else {
    include("language/CZUser-Info/CZUser-Info-turkish.php");
 }

//Lastuser Name
function last_user() {
    global $db, $prefix;
    $sql = "SELECT username FROM ".$prefix."_users WHERE user_active = 1 AND user_level > 0 ORDER BY user_id DESC LIMIT 1";
    list($lastuser) = $db->sql_fetchrow($db->sql_query($sql));
    return $lastuser;
}

//Total Members
function numusers() {
    global $prefix, $db;
    $sql = "SELECT COUNT(*) FROM ".$prefix."_users WHERE user_id > 1";
    list($numrows) = $db->sql_fetchrow($db->sql_query($sql));
    $numrows = number_format($numrows); 
    return $numrows;
}

//Total Waiting
function waiting_users() {
    global $prefix, $db;
    $sql = "SELECT COUNT(*) FROM ".$prefix."_users_temp";
    list($numrowswaiting) = $db->sql_fetchrow($db->sql_query($sql));
    return $numrowswaiting;
}

//New Users Today and Yesterday
function new_users() {
    global $prefix, $db;
    $sql = "SELECT COUNT(*) FROM ".$prefix."_users WHERE user_regdate='".date("M d, Y")."'";
    list($userCount[0]) = $db->sql_fetchrow($db->sql_query($sql));

    $sql = "SELECT COUNT(*) FROM ".$prefix."_users WHERE user_regdate='".date("M d, Y", time()-86400)."'";
    list($userCount[1]) = $db->sql_fetchrow($db->sql_query($sql));
    return $userCount;
}

if ($dopmpopup == 1) {
    if ($userinfo['user_popup_pm'] && $userinfo['user_new_privmsg']) { 
       $content .= "<script language=\"Javascript\" type=\"text/javascript\"> 
<!-- 
        window.open('modules.php?name=Private_Messages&file=index&mode=newpm&popup=1', '', 'HEIGHT=225,resizable=yes,WIDTH=400'); 
//--> 
</script>"; 
   } 
}   
    //Registered users online
    $members = $db->sql_query("SELECT w.uname, w.module, w.url, u.user_id, u.user_level, u.user_allow_viewonline FROM ".$prefix."_session AS w LEFT JOIN ".$prefix."_users AS u ON u.username = w.uname WHERE guest = '0' ORDER by u.user_id ASC");
    $guests = $db->sql_query("SELECT uname FROM ".$prefix."_session WHERE guest ='1'");

    //Online Total data
    $online_num[0] = $db->sql_numrows($members);
    $online_num[1] = $db->sql_numrows($guests);
    $online_num[2] = $online_num[0] + $online_num[1];

    //Assemble the online registered users 
    $who_online_now = ""; 
    $i = 1; 
    while ($session = $db->sql_fetchrow($members)) {
    //Allow View?
    if ($session['user_allow_viewonline'] || is_admin($admin)) { 
    if ($i < 10) $czi = "0$i"; else $czi = $i;

     //$uid = intval($session['user_id']);
     $uname = $session['uname']; 
     $ulevel = intval($session['user_level']);  
     $mod = $session['module'];
     $url = $session['url'];

   if ($Version_Num < 7.6) {
     if(preg_match("/admin/", $url)) {
     $mod = "Private";
     $url = "index.php"; 
     }
   } elseif ($Version_Num >= 7.6) {
     if(preg_match("/".$admin_file."/", $url)) {
     $mod = "Private";
     $url = "index.php"; 
     }
   }
      if ((is_admin($admin)) && ($showonlyadmin == 0)) {
          $where = "<a HREF=\"$url\" title=\"$mod\">$czi</a>.&nbsp;";
      } elseif ($showonlyadmin == 1) {
          $where = "<a HREF=\"$url\" title=\"$mod\">$czi</a>.&nbsp;";
      } else {
          $where = "$czi.&nbsp;";
      }

                 if ($ulevel == 2) {
                 $who_online_now .= "<br />$where<A HREF=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$uname\"  title=\""._CZ_VIEW." $uname's "._CZ_VIEWPP."\">$uname</a>&nbsp;<img src=\"images/CZUser/admin.gif\">\n"; 
                 } 
                 elseif ($ulevel == 3) {
                 $who_online_now .= "<br />$where<A HREF=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$uname\"  title=\""._CZ_VIEW." $uname's "._CZ_VIEWPP."\">$uname</a></font>&nbsp;<img src=\"images/CZUser/staff.gif\">\n"; 
                 }
                 else {
           $who_online_now .= "<br />$where<A HREF=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$uname\" title=\""._CZ_VIEW." $uname's "._CZ_VIEWPP."\">$uname</a></font>\n"; 
          } 
      $who_online_now .= ( $i != $online_num[0] ? "" : "" ); 
      $i++; 
   
      } else {
      $hidden++;
   }
 } //Allow View
$db->sql_freeresult($members);

   //Mostonline data
   $result = $db->sql_query("SELECT total, members, nonmembers FROM ".$prefix."_mostonline");
   $row = $db->sql_fetchrow($result);
   $total = intval($row['total']);
   $members = intval($row['members']);
   $nonmembers = intval($row['nonmembers']);
   $db->sql_freeresult($result);

   //Break Mostonline Total?
   if ($total < $online_num[2]) {
   $db->sql_query("DELETE FROM ".$prefix."_mostonline WHERE total='$total' LIMIT 1");
   $db->sql_query("INSERT INTO ".$prefix."_mostonline VALUES ('$online_num[2]','$online_num[0]','$online_num[1]')");
   }

   if (is_user($user)) {
   //Greet User
   $urname = $userinfo['username'];
   $content .= "<img src=\"images/CZUser/user.gif\"><br />&nbsp;\n";
   $content .= "<script language=\"JavaScript\">\n";
   $content .= "welcome_user();\n";
   $content .= "function welcome_user() {\n";
   $content .= "var thedate;\n";
   $content .= "var thehour;\n";
   $content .= "thedate = new Date();\n";
   $content .= "thehour = thedate.getHours();\n";    
   $content .= "if (thehour <12)\n";
   $content .= "document.write(\""._CZ_GOODMORNINGUSER."$urname\")\n";
   $content .= "else if (thehour < 17)\n";
   $content .= "document.write(\""._CZ_GOODAFTERNOONUSER."$urname\")\n";
   $content .= "else\n";
   $content .= "document.write(\""._CZ_GOODEVENINGUSER."$urname\")\n";
   $content .= "}\n";
   $content .= "</script>\n";

if ($useavatars == 1) {
   //Avatars...
   $bbconf = array();
   $result = $db->sql_query("SELECT * FROM ".$prefix."_bbconfig");
   while(list($config_name, $config_value) = $db->sql_fetchrow($result)){
	   $bbconf[$config_name] = $config_value;
   }
  if ($userinfo['user_allowavatar']) {
   if ($userinfo['user_avatar_type'] == 1)  { 
   $content .= "<br /><br /><center><img src=\"".$bbconf['avatar_path']."/".$userinfo['user_avatar']."\"></center><br />\n"; 
   } elseif ($userinfo['user_avatar_type'] == 2) { 
   $content .= "<br /><br /><center><img src=\"".$userinfo['user_avatar']."\"></center><br />\n"; 
   } elseif ($userinfo['user_avatar'] == "") { 
   $content .= "<br /><br /><center><img src=\"".$bbconf['avatar_gallery_path']."/gallery/blank.gif\"></center>\n"; 
   } else {
   $content .= "<br /><br /><center><img src=\"".$bbconf['avatar_gallery_path']."/".$userinfo['user_avatar']."\"></center><br />\n"; 
   }
  }
}

if ($usebbranks == 1) {
   //Ranks...
   $result_rank = $db->sql_query("SELECT * FROM ".$prefix."_bbranks ORDER BY rank_special, rank_min");
   $ranksrow = array();
   while ( $row = $db->sql_fetchrow($result_rank) ) {
           $ranksrow[] = $row;
   }
   $db->sql_freeresult($result_rank);

        if ($userinfo['user_rank']) {
            for($j = 0; $j < count($ranksrow); $j++) {
              if ($userinfo['user_rank'] == $ranksrow[$j]['rank_id'] && $ranksrow[$j]['rank_special']) {
                  $poster_rank = $ranksrow[$j]['rank_title'];
                  $rank_image = ($ranksrow[$j]['rank_image']) ? '<img src="'.$ranksrow[$j]['rank_image'].'" alt="'.$poster_rank.'" title="'.$poster_rank.'" border="0"><br />' : '';
              }
            }
        } else {
           for($j = 0; $j < count($ranksrow); $j++) {
             if ($userinfo['user_posts'] >= $ranksrow[$j]['rank_min'] && !$ranksrow[$j]['rank_special']) {
                  $poster_rank = $ranksrow[$j]['rank_title'];
                  $rank_image = ($ranksrow[$j]['rank_image']) ? '<img src="'.$ranksrow[$j]['rank_image'].'" alt="'.$poster_rank.'" title="'.$poster_rank.'" border="0"><br />' : '';
             }
           }
        }
   $content .= "<center>".$rank_image."".$poster_rank."</center>\n";
}

   //Line to separate
   $content .= "<hr noShade>";
   $content .= "<a href=\"modules.php?name=Your_Account\" title=\""._CZ_GOHOME."\"><img src=\"images/CZUser/home.gif\" border=\"0\"></a>\n";
   $content .= "<u><b>"._CZ_ACCOUNTINFO."</u></b><br />\n";
  if ($showpoints == 1) {
   $userpoints = number_format($userinfo[$sitepoints]);
   $content .= "<img src=\"images/CZUser/li.gif\" align=\"absmiddle\">\n";
   $content .= ""._CZ_POINTS."$userpoints<br />\n";
  }
  if ($showpms == 1) {
   $pms = $userinfo['user_new_privmsg'];
   $content .= "<img src=\"images/CZUser/li.gif\" align=\"absmiddle\">\n";
   $content .= ""._CZ_PRUNREAD."<b><a title=\""._CZ_CHECKPMS."\" href=\"modules.php?name=Private_Messages\">$pms</a></b><br />\n";
  } 
   $content .= "<img src=\"images/CZUser/li.gif\" align=\"absmiddle\">\n";
   $content .= "<a title=\""._CZ_LOGOUT."\" href=\"modules.php?name=Your_Account&amp;op=logout\">"._CZ_LOGOUT."</a><br />\n";
   //Line to separate
   $content .= "<hr noShade>";

   } else {
 
   //Display LOGIN information for Guests Only 
          mt_srand ((double)microtime()*1000000);
	    $maxran = 1000000;
	    $random_num = mt_rand(0, $maxran);

   //Greet Guest 
   $content .= "<img src=\"images/CZUser/user.gif\">&nbsp;\n";
   $content .= "<script language=\"JavaScript\">\n";
   $content .= "welcome_guest();\n";
   $content .= "function welcome_guest() {\n";
   $content .= "var thedate;\n";
   $content .= "var thehour;\n";
   $content .= "thedate = new Date();\n";
   $content .= "thehour = thedate.getHours();\n";    
   $content .= "if (thehour <12)\n";
   $content .= "document.write(\""._CZ_GOODMORNINGGUEST."\")\n";
   $content .= "else if (thehour < 17)\n";
   $content .= "document.write(\""._CZ_GOODAFTERNOONGUEST."\")\n";
   $content .= "else\n";
   $content .= "document.write(\""._CZ_GOODEVENINGGUEST."\")\n";
   $content .= "}\n";
   $content .= "</script>\n";

   //Line to separate
   $content .= "<hr noShade>";
 
   //Links to Register or Regain Password
   $content .= "<img src=\"images/CZUser/li.gif\" align=\"absmiddle\">\n";
   $content .= "<a href=\"modules.php?name=Your_Account&amp;op=new_user\">"._CZ_REGISTER."</a><br />\n"; 
   $content .= "<img src=\"images/CZUser/li.gif\" align=\"absmiddle\">\n";
   $content .= "<a href=\"modules.php?name=Your_Account&op=pass_lost\">"._CZ_LOSTPASSWORD."</a><br /><br />\n";

   //LOGIN Box
   $content .= "<table border=\"0\">\n"; 
   $content .= "<form action=\"modules.php?name=Your_Account\" method=\"post\">\n";
   $content .= "<tr><td><input type=\"text\" name=\"username\" size=\"15\" maxlength=\"25\" value=\"&lt;username&gt;\" onFocus=\"if(this.value=='&lt;username&gt;')this.value='';\"></td></tr>\n"; 
   $content .= "<tr><td><input type=\"password\" name=\"user_password\" size=\"15\" maxlength=\"20\" value=\"&lt;password&gt;\" onFocus=\"if(this.value=='&lt;password&gt;')this.value='';\"></td></tr>\n";
   if (extension_loaded("gd") AND ($gfx_chk == 2 OR $gfx_chk == 4 OR $gfx_chk == 5 OR $gfx_chk == 7)) {
   if ($Version_Num < 7.5) {
       $security_code_url = "modules.php?name=Your_Account&op=gfx&random_num=$random_num";
   } elseif ($Version_Num >= 7.5) {
       $security_code_url = "?gfx=gfx&random_num=$random_num";
   }
   $content .= "<tr><td colspan='2'>"._CZ_SECURITYCODE." <img src='$security_code_url' border='1' alt='"._SECURITYCODE."' title='"._SECURITYCODE."'></td></tr>\n"; 
   $content .= "<tr><td colspan='2'>"._CZ_TYPESECCODE." <input type=\"text\" NAME=\"gfx_check\" SIZE=\"12\" MAXLENGTH=\"10\"></td></tr>\n"; 
   $content .= "<input type=\"hidden\" name=\"random_num\" value=\"$random_num\">\n"; 
   } else {
   $content .= "<input type=\"hidden\" name=\"random_num\" value=\"$random_num\">";
   $content .= "<input type=\"hidden\" name=\"gfx_check\" value=\"$code\">";
   }
   $content .= "</table><input type=\"hidden\" name=\"redirect\" value=$redirect>\n"; 
   $content .= "<input type=\"hidden\" name=\"mode\" value=$mode>\n"; 
   $content .= "<input type=\"hidden\" name=\"f\" value=$f>\n"; 
   $content .= "<input type=\"hidden\" name=\"t\" value=$t>\n"; 
   $content .= "<input type=\"hidden\" name=\"op\" value=\"login\">\n"; 
   $content .= "&nbsp;<input type=\"submit\" value=\""._LOGIN."\"></form>\n";

   //Line to separate
   $content .= "<hr noShade>"; 
   } 



   // Info for users who are logged in AND Guests 
      $last = new_users();
      $lastuser = last_user();

   $content .= "<a href=\"modules.php?name=Members_List\" title=\""._CZ_MEMBERSLIST."\"><img src=\"images/CZUser/members.gif\" border=\"0\"></a>\n";
   $content .= "<u><b>"._CZ_MEMBERSHIP."</u></b><br />\n";
   $content .= "<img src=\"images/CZUser/li.gif\" align=\"absmiddle\"> "._CZ_TODAY."<b>".$last[0]."</b><br />\n"; 
   $content .= "<img src=\"images/CZUser/li.gif\" align=\"absmiddle\"> "._CZ_YESTERDAY."<b>".$last[1]."</b></b><br />\n";
   $content .= "<img src=\"images/CZUser/li.gif\" align=\"absmiddle\"> "._CZ_WAITING."<b>".waiting_users()."</b><br />\n";
   $content .= "<img src=\"images/CZUser/li.gif\" align=\"absmiddle\"> "._CZ_TOTALMEMBERS."<b>".numusers()."</b><br />\n";
   $content .= "<img src=\"images/CZUser/li.gif\" align=\"absmiddle\"> "._CZ_LATEST."\n";
   $content .= "<a title=\""._CZ_VIEW." $lastuser's "._CZ_VIEWPP."\" href=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$lastuser\"><b>$lastuser</b></a><br />\n";

   //Line to separate
   $content .= "<hr noShade>";

   //Mostonline
   if ($showmost==1) {
   $content .= "<a href=\"modules.php?name=Statistics\" title=\""._CZ_STATS."\"><img src=\"images/CZUser/stats.gif\" border=\"0\"></a>\n";
   $content .= "<u><b>"._CZ_MOSTONLINE."</u></b><br />\n";
   $content .= "<img src=\"images/CZUser/li.gif\" align=\"absmiddle\"> "._CZ_VISITORS."<b>".number_format($nonmembers)."</b><br />\n";
   $content .= "<img src=\"images/CZUser/li.gif\" align=\"absmiddle\"> "._CZ_MEMBERS."<b>".number_format($members)."</b><br />\n";
   $content .= "<img src=\"images/CZUser/li.gif\" align=\"absmiddle\"> "._CZ_TOTALONLINE."<b>".number_format($total)."</b><br />\n";

   //Line to separate
   $content .= "<hr noShade>";

  }//Show Most
 
   //Total Online
   $content .= "<img src=\"images/CZUser/group.gif\">\n";
   $content .= "<u><b>"._CZ_ONLINEINFO."</u></b><br />\n";
   $content .= "<img src=\"images/CZUser/li.gif\" align=\"absmiddle\"> "._CZ_VISITORS."<b>".number_format($online_num[1])."</b><br />\n";
   $content .= "<img src=\"images/CZUser/li.gif\" align=\"absmiddle\"> "._CZ_MEMBERS."<b>".number_format($online_num[0])."</b><br />\n";
  if ($hidden ==""){ $hidden = "0"; }
  if ($hidden == 0) {
   } else { 
   $content .= "<img src=\"images/CZUser/li.gif\" align=\"absmiddle\"> "._CZ_HIDDENUSERS."<b>$hidden</b><br />\n";
} 
   $content .= "<img src=\"images/CZUser/li.gif\" align=\"absmiddle\"> "._CZ_TOTALONLINE."<b>".number_format($online_num[2])."</b><br />\n";

   //Users Online List 
if (is_user($user) || is_admin($admin)) {

   //Line to separate
   $content .= "<hr noShade>";
   $content .= "<img src=\"images/CZUser/online.gif\">\n";
   $content .= "<b><u>"._CZ_ONLINELIST."</b></u>\n";
 if ($online_num[0]>10) {
   $content .= "<div style=\"border: 0pt none; height: 100px; width: 100%; overflow: auto;\">";
   $content .= "$who_online_now\n";
   $content .= "</div>"; 
 } else {
   $content .= "$who_online_now\n";
 } 
} 
?>